package com.hurui.xiaoming.activity.me;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.hurui.xiaoming.R;
import com.hurui.xiaoming.activity.BaseActivity;
import com.hurui.xiaoming.adapter.ProgressAdapter;
import com.hurui.xiaoming.bean.Li_ProgressRersult;
import com.hurui.xiaoming.http.ApiClient;
import com.hurui.xiaoming.http.ApiSevice;
import com.hurui.xiaoming.utils.DefultData;
import com.hurui.xiaoming.utils.WriteReadSharedPrefs;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MyProgressActivity extends BaseActivity {
    private ImageView back_iv;
    private TextView title_tv;
    XRecyclerView creaditor_rv;
    Map map = new HashMap();
    ProgressAdapter adapter;
    List list = new ArrayList();
    public ApiSevice apiSevice = ApiClient.getModel().getService();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_progress);

        initView();
        initAction();
    }

    @Override
    protected void onStart() {
        super.onStart();
        getIntentData();
    }

    @Override
    public void initView() {
        back_iv = (ImageView) findViewById(R.id.back_iv);
        title_tv = (TextView) findViewById(R.id.top_title_tv);
        title_tv.setText("进度查询");

        creaditor_rv = (XRecyclerView) findViewById(R.id.creaditor_rv);
        creaditor_rv.setLayoutManager(new LinearLayoutManager(this,
                LinearLayoutManager.VERTICAL,false));
        adapter = new ProgressAdapter(mContext,list);
        creaditor_rv.setAdapter(adapter);
    }

    @Override
    public void initAction() {
        getIntentData();
        back_iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onFinish();
            }
        });
    }

    /**
     * 获取网络数据
     */
    public void getIntentData(){
        map.clear();
        map.put("oi_state","9");
        map.put("ui_id", WriteReadSharedPrefs.readUserID(mContext));
        // map.put("ui_id", "1");
        Call<Li_ProgressRersult> call = apiSevice.onHttpPostGetProgress(DefultData.selectProgress,map);
        call.enqueue(new Callback<Li_ProgressRersult>() {
            @Override
            public void onResponse(Call<Li_ProgressRersult> call, Response<Li_ProgressRersult> response) {
                if(response.isSuccessful()){
                    Li_ProgressRersult li_progressRersult = response.body();

                    List<Li_ProgressRersult.DataBean> data = li_progressRersult.getData();
                    adapter.refreshData(data);
                    creaditor_rv.refreshComplete();
                    creaditor_rv.loadMoreComplete();
//                Toast.makeText(getActivity(),"请求成功",Toast.LENGTH_SHORT).show();

                }else{

                    //    onToast("失败000");
                }
            }

            @Override
            public void onFailure(Call<Li_ProgressRersult> call, Throwable t) {
                Toast.makeText(MyProgressActivity.this,t.getMessage(),Toast.LENGTH_SHORT).show();
                onHttpFail( -1 , t.getMessage());
                creaditor_rv.refreshComplete();
                creaditor_rv.loadMoreComplete();
            }
        });
    }
}
